<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			.box{
				width: 200px;
				height: 200px;
				background: red;
				position: relative;
				opacity: 0.9;
				margin: 100px ;
				border: solid 1px black;
			}
			.box2{
				width: 100px;
				height:100px;
				border: solid 5px gold;
				padding: 10px;
				background: blue;
				/*position: absolute;
				left: 50px;
				top: 50px;*/
				margin: 20px 0px 0px 50px;
				position: relative;
				top: 30px;
				left: 20px;
			}
			body{
				height: 2000px;
				width: 3000px;
			}
		</style>
		<script src="js/jquery-3.6.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			$(function(){
				//访问匹配元素的样式属性。
				console.log($(".box").css("position"));
				//$(".box").css("width","50%");
				$(".box").css({"width":"300px","height":"300px"});
				
				//获取匹配元素在当前视口的相对偏移。
				console.log($(".box2").offset().top);
				console.log($(".box2").offset().left);
				
				//获取匹配元素相对父元素的偏移。
				console.log($(".box2").position().top);
				console.log($(".box2").position().left);
				
				//获取匹配元素相对滚动条顶部的偏移和左侧的偏移
				$(window).scroll(function(){
					//console.log($("html,body").scrollTop())
					console.log($("html,body").scrollLeft())
				})
				
				//height,innerHeight,outerHeight
				// width,innerWidth,outerWidth
				console.log($(".box2").width());//width
				console.log($(".box2").innerWidth());//width+padding
				console.log($(".box2").outerWidth());//width+padding+border
			})
		</script>
	</head>
	<body>
		<div class="box">
			<div class="box2"></div>
		</div>
	</body>
</html>
